package com.example.list;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;

public class DialogActivity extends AppCompatActivity {
    private AlertDialog.Builder builder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog);

        showDialog3();

    }

    void showDialog1() {
        builder = new AlertDialog.Builder(this)
//                .setIcon(R.mipmap.ic_launcher)
                .setTitle("下单成功")
                .setMessage("订单号：243533").setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //ToDo: 你想做的事情

                    }
                })
                .setNegativeButton("取消（消极）", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //ToDo: 你想做的事情
                        Toast.makeText(DialogActivity.this, "关闭按钮", Toast.LENGTH_LONG).show();
                        dialogInterface.dismiss();
                    }
                })
        ;
        builder.create().show();
    }

    public void showDialog2() {
        final CustomEditTextDialog customDialog = new CustomEditTextDialog(this);
        final EditText editText = (EditText) customDialog.getEditText();//方法在CustomDialog中实现
        customDialog.getTvAccount().setText("1818231980");
        customDialog.setOnSureListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(DialogActivity.this, "你点击了确定,输入的值为:" + editText.getText().toString(), Toast.LENGTH_SHORT).show();
                customDialog.dismiss();
            }
        });
        customDialog.setOnCanlceListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast toast=Toast.makeText(DialogActivity.this, "密码错误", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER,0,0);
                toast.show();
                customDialog.dismiss();
            }
        });
        customDialog.setTile("普通账号");
        customDialog.show();
    }
    public void showDialog3() {
        final EditTextDialog customDialog = new EditTextDialog(this,0);
        customDialog.setTile("普通账号");
        customDialog.setData("100","招行存管");
        customDialog.setOnSureListener(new EditTextDialog.EditTextListener() {
            @Override
            public void getEtContent(String content) {
                Toast.makeText(DialogActivity.this, "你点击了确定,输入的值为:" + content, Toast.LENGTH_SHORT).show();
                customDialog.dismiss();
            }
        });
        customDialog.setOnCanlceListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                customDialog.dismiss();
            }
        });

        customDialog.show();

        WindowManager windowManager = getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = customDialog.getWindow().getAttributes();
        lp.width = (int)(display.getWidth()); //设置宽度
        lp.height = (int)(display.getHeight()); //设置高度
        customDialog.getWindow().setAttributes(lp);
    }


}